<template>
  <!-- 放置一个图标 -->
  <!-- fullscreen箭头向外 exit-fullscreen箭头向内 -->
  <div>
    <svg-icon :icon-class="isFullScreen ? 'exit-fullscreen' : 'fullscreen'" class="fullscreen" @click="toggleScreenFullFn" />
  </div>
</template>

<script>
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isFullScreen: false // false未进入全屏状态
    }
  },
  created() {
    // 检测全屏状态改变
    // 点击screenfull.isFullscreen值为true 按esc为false
    screenfull.on('change', () => {
      this.isFullScreen = screenfull.isFullscreen
    })
  },
  methods: {
    // 全屏图形的点击事件
    toggleScreenFullFn() {
      this.isFullScreen = !this.isFullScreen
      screenfull.toggle() // 如果当前是全屏就退出，如果不是全屏就进入
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
  margin-right: 10px;
}
</style>
